import Vue from 'vue'
import VueRouter from 'vue-router'

import login from '../views/home/login.vue'
import home from '../views/home/home.vue'
import index from '../views/home/index.vue'
import profile from '../views/home/profile.vue'

import company from '../views/systems/company.vue'
import option from '../views/systems/option.vue'
import store from '../views/systems/store.vue'
import sysUser from '../views/authorty/sysUser.vue'
import smsTemplate from '../views/systems/template/Index.vue'

import menu from '../views/authorty/menu/Index.vue'
import role from '../views/authorty/role.vue'

import product from '../views/product/product.vue'

import video from '../views/video/video.vue'
import hospital from '../views/doctor/hospital.vue'
import doctor from '../views/doctor/doctor.vue'

import order from '../views/order/order.vue'

import rule from '../views/market/rule.vue'
import checkActivity from '../views/checkManager/checkActivity.vue'
import customer from '../views/market/customer.vue'
import news from '../views/market/news.vue'
import ticket from '../views/market/ticket.vue'
import advert from '../views/market/advert.vue'
import doctorOrder from '../views/doctor/doctorOrder.vue'
import agent from '../views/market/agent.vue'
import punchcard from '../views/punchcard/punchcard.vue'
import orderApply from '../views/order/orderApply.vue'
import message from '../views/message/message.vue'
import activity from '../views/market/activity.vue'
import checkReport from '../views/checkManager/checkReport.vue'
import drawCash from '../views/financeManager/drawCash.vue'

import myOrder from '../views/doctorRole/myOrder.vue'
import myRecommender from '../views/doctorRole/myRecommender.vue'
import myIncomeFlow from '../views/doctorRole/myIncomeFlow.vue'
import doctorOrderSort from '../views/doctor/doctorOrderSort.vue'

Vue.use(VueRouter);

const routes = [{
	path: '',
	name: '登录',
	component: login
}, {
	path: '/login',
	name: '登录',
	component: login
}, {
	path: '/home',
	name: '系统管理',
	component: home,
	redirect: '',
	children: [{
	    path: '/index',
	    name: '首页',
	    component: index
    }, {
	    path: '/profile',
	    name: '个人中心',
	    component: profile
    }, {
		path: '/company',
		name: '公司管理',
		component: company
	}, {
		path: '/store',
		name: '门店管理',
		component: store
	}, {
		path: '/option',
		name: '选项管理',
		component: option
	}, {
		path: '/menu',
		name: '菜单管理',
		component: menu
	}, {
		path: '/sysUser',
		name: '用户管理',
		component: sysUser
	}, {
		path: '/role',
		name: '角色管理',
		component: role
	}, {
		path: '/order',
		name: '订单管理',
		component: order
	}, {
		path: '/advert',
		name: '广告管理',
		component: advert
	}, {
		path: '/ticket',
		name: '优惠券管理',
		component: ticket
	}, {
		path: '/product',
		name: '产品管理',
		component: product
	}, {
		path: '/news',
		name: '新闻管理',
		component: news
	}, {
		path: '/video',
		name: '视频管理',
		component: video
	}, {
		path: '/hospital',
		name: '医院管理',
		component: hospital
	}, {
		path: '/doctor',
		name: '医生管理',
		component: doctor
	}, {
		path: '/rule',
		name: '规则管理',
		component: rule
	}, {
		path: '/checkActivity',
		name: '筛查管理',
		component: checkActivity
	}, {
		path: '/customer',
		name: '客户管理',
		component: customer
	}, {
		path: '/smsTemplate',
		name: '短信模块',
		component: smsTemplate
	}, {
		path: '/doctorOrder',
		name: '咨询管理',
		component: doctorOrder
	}, {
		path: '/agent',
		name: '代理管理',
		component: agent
	}, {
		path: '/punchcard',
		name: '打卡管理',
		component: punchcard
	}, {
		path: '/orderApply',
		name: '售后管理',
		component: orderApply
	}, {
		path: '/message',
		name: '消息管理',
		component: message
	}, {
		path: '/activity',
		name: '优惠活动管理',
		component: activity
	}, {
		path: '/checkReport',
		name: '筛查报告管理',
		component: checkReport
	}, {
		path: '/drawCash',
		name: '佣金提取管理',
		component: drawCash
	}, {
		path: '/myOrder',
		name: '我的咨询',
		component: myOrder
	}, {
		path: '/myRecommender',
		name: '我的粉丝',
		component: myRecommender
	}, {
		path: '/myIncomeFlow',
		name: '我的收益',
		component: myIncomeFlow
	}, {
		path: '/doctorOrderSort',
		name: '咨询排名',
		component: doctorOrderSort
	}]
}];

const router = new VueRouter({
	// mode: 'history',
	routes: routes
})

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

router.beforeEach((to, from, next) => {
	var token = sessionStorage.getItem('token');
	if(to.path != '/' && to.path != '/login') {
		if (token === null || token === "") {
			router.push('/');
			return;
		}
	}
	/* if (store.state.permissions.includes[to.meta.permissions]) {
		router.push(to.redirect);
		return;
	} */
	next();
})

router.afterEach((to, from) => {
	
})

export default router
